import media from '@ohos.multimedia.media';
export class AVPlayerClass {
    static async playAudio(t34) {
        if (!AVPlayerClass.avPlayer) {
            AVPlayerClass.avPlayer = await media.createAVPlayer();
        }
        if (t34) {
            AVPlayerClass.audioName = t34;
            AVPlayerClass.setAvPlayerName(getContext());
        }
    }
    static async setAvPlayerName(p34) {
        try {
            let r34 = await p34.resourceManager.getRawFd(AVPlayerClass.audioName);
            let s34 = { fd: r34.fd, offset: r34.offset, length: r34.length };
            if (!AVPlayerClass.isSettingBack) {
                AVPlayerClass.setAvPlayerCallBack();
            }
            if (AVPlayerClass.avPlayer) {
                AVPlayerClass.avPlayer.fdSrc = s34;
            }
        }
        catch (q34) {
            AlertDialog.show({
                message: q34.message
            });
        }
    }
    static setAvPlayerCallBack() {
        if (AVPlayerClass.avPlayer) {
            AVPlayerClass.isSettingBack = true;
            AVPlayerClass.avPlayer.on('seekDone', (o34) => {
                AVPlayerClass.avPlayer.play();
            });
            AVPlayerClass.avPlayer.on('stateChange', async (m34, n34) => {
                switch (m34) {
                    case 'initialized':
                        console.info('AVPlayer state initialized called.');
                        AVPlayerClass.avPlayer.prepare();
                        break;
                    case 'prepared':
                        console.info('AVPlayer state prepared called.');
                        AVPlayerClass.avPlayer.seek(0);
                        break;
                    case 'playing':
                        console.info('AVPlayer state playing called.');
                        break;
                    case 'paused':
                        console.info('AVPlayer state paused called.');
                        break;
                    case 'completed':
                        console.info('AVPlayer state completed called.');
                        AVPlayerClass.avPlayer.reset();
                        break;
                    case 'stopped':
                        console.info('AVPlayer state stopped called.');
                        break;
                    case 'released':
                        console.info('AVPlayer state released called.');
                        break;
                    default:
                        console.info('AVPlayer state unknown called.');
                        break;
                }
            });
        }
    }
}
AVPlayerClass.avPlayer = null;
AVPlayerClass.audioName = '';
AVPlayerClass.isSettingBack = false;
